﻿using System;
using System.Text;
using System.Web.Mvc;
using ProjectMadaktariMVC.Models;
using System.Collections.Generic;

namespace ProjectMadaktariMVC.Helpers
{
    public class ConfigurationHelper
    {

        public static string HospitalDropDown(string name, int? hospitalId)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<select name=\"").Append(name).Append("\">\n");

            foreach (Hospital h in ConfigurationDAO.GetHospitals())
            {
                sb.Append("<option value=\"").Append(h.hospitalID).Append("\" ");
                if (h.hospitalID == hospitalId)
                    sb.Append("selected=\"true\" ");
                sb.Append(">").Append(h.hospitalName).Append("</option>\n");
            }

            sb.Append("</select>\n");
            return sb.ToString();
        }

        public static string HospitalDropDown(string name)
        {
            return HospitalDropDown(name, -1);
        }

        public static string ReferalLocationDropdown(string name, int? referalLocationId)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<select name=\"").Append(name).Append("\">\n");

            foreach(ReferalLocation rf in ConfigurationDAO.GetReferalLocations())
            {
                sb.Append("<option value=\"").Append(rf.referalLocationID).Append("\" ");
                if (rf.referalLocationID == referalLocationId)
                    sb.Append("selected=\"true\" ");
                sb.Append(">").Append(rf.referalLocationName).Append("</option>\n");
            }

            sb.Append("</select>\n");


            return sb.ToString();
        }

        public static string ReferalLocationDropdown(string name)
        {
            return ReferalLocationDropdown(name, -1);
        }

        public static string DiagnosisList(string name, int episodeId)
        {
            EpisodeDAO episodeDAO = new EpisodeDAO();
            StringBuilder sb = new StringBuilder();
            StringBuilder sbRight = new StringBuilder();
            StringBuilder sbLeft = new StringBuilder();
            int i = 1;
            foreach (Diagnosi d in ConfigurationDAO.GetDiagnoses())
            {
                StringBuilder tempSb;

                if (i % 2 == 0)
                {
                    tempSb = sbRight;
                }
                else
                {
                    tempSb = sbLeft;
                }
                tempSb.Append("<input type=\"checkbox\" name=\"").Append(name).Append("\" value=\"").Append(d.diagnosisID).Append("\" ");
                if (episodeDAO.EpisodeHasDiagnosis(episodeId, d.diagnosisID))
                {
                    tempSb.Append("checked=\"true\" ");
                }
                tempSb.Append("/>");
                tempSb.Append(d.diagnosisName).Append("<br />");
                i++;
            }

            sb.Append("<div class=\"block1\">").Append(sbLeft.ToString()).Append("</div><div class=\"block2\">").Append(sbRight.ToString()).Append("</div>");

            return sb.ToString();
        }

        public static string DiagnosisList(string name)
        {
            return DiagnosisList(name, -1);
        }

        public static string ConcomitantDiagnosisDropDown(string name, int? concomitantDiagnosisId)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<select name=\"").Append(name).Append("\">\n");

            sb.Append("<option></option>\n");

            foreach (ConcomitantDiagnosi cd in ConfigurationDAO.GetConcomitantDiagnoses())
            {
                sb.Append("<option value=\"").Append(cd.concomitantDiagnosisID).Append("\" ");
                if (cd.concomitantDiagnosisID == concomitantDiagnosisId)
                {
                    sb.Append("selected=\"true\" ");
                }
                sb.Append(">").Append(cd.concomitantDiagnosisName).Append("</option>\n");
            }

            sb.Append("</select>\n");

            return sb.ToString();
        }

        public static string PostOpStatusDropDown(string name, string value)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<select name=\"").Append(name).Append("\">\n");
            string[] postOpStatuses = { "Doing Fine", "Stable", "Unstable", "Critical" };
            sb.Append("<option value=\"\"></option>\n");
            foreach (string s in postOpStatuses)
            {
                sb.Append("<option value=\"").Append(s).Append("\" ");
                if (s.Equals(value))
                {
                    sb.Append("selected=\"true\" ");
                }
                sb.Append(" >").Append(s).Append("</option>\n");
            }

            sb.Append("</select>\n");

            return sb.ToString();
        }
        public static string ComplicationsRadioButtons(string name, bool? value)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<input type=\"radio\" value=\"true\" name=\"").Append(name).Append("\" ");
            if (value == true)
            {
                sb.Append("checked=\"true\" ");
            }
            sb.Append("/> Yes <input type=\"radio\" value=\"false\" name=\"").Append(name).Append("\" ");
            if (value == false)
            {
                sb.Append("checked=\"true\" ");
            }

            sb.Append("/> No");

            return sb.ToString();
        }

        public static string FollowUpStatusDropdown(string name, string value)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<select name=\"").Append(name).Append("\">\n");
            string[] statuses = { "Functional", "Slightly Disabled", "Disabled" };
            sb.Append("<option value=\"\"></option>");
            foreach (string s in statuses)
            {
                sb.Append("<option value=\"").Append(s).Append("\" ");
                if (s.Equals(value))
                {
                    sb.Append("selected=\"true\" ");
                }
                sb.Append(">").Append(s).Append("</option>\n");
            }

            sb.Append("</select>");
            return sb.ToString();
        }

        public static string AnestesiaRadioButtons(string name, string value)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<select name=\"").Append(name).Append("\">\n");
            string[] statuses = { "Yes", "No", "Maybe" };
            sb.Append("<option value=\"\"></option>");
            foreach (string s in statuses)
            {
                sb.Append("<option value=\"").Append(s).Append("\" ");
                if (s.Equals(value))
                {
                    sb.Append("selected=\"true\" ");
                }
                sb.Append(">").Append(s).Append("</option>\n");
            }

            sb.Append("</select>\n");
            return sb.ToString();
        }
        public static string SurgicalComplicationsRadioButtons(string name, bool? value)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<input type=\"radio\" value=\"true\" name=\"").Append(name).Append("\" ");
            if (value == true)
            {
                sb.Append("checked=\"true\" ");
            }
            sb.Append("/> Yes <input type=\"radio\" value=\"false\" name=\"").Append(name).Append("\" ");
            if (value == false)
            {
                sb.Append("checked=\"true\" ");
            }

            sb.Append("/> No");

            return sb.ToString();
        }
        public static string ProcedureDropDown(string name, int? procedureTypeId)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<select name=\"").Append(name).Append("\">\n");

            foreach (ProcedureType pt in ConfigurationDAO.GetProcedureTypes())
            {
                sb.Append("<option value=\"").Append(pt.procedureTypeID).Append("\" ");
                if (pt.procedureTypeID == procedureTypeId)
                    sb.Append("selected=\"true\" ");
                sb.Append(">").Append(pt.procedureTypeName).Append("</option>\n");
            }

            sb.Append("</select>\n");
            return sb.ToString();
        }

        public static string ProcedureDropDown(string name)
        {
            return ProcedureDropDown(name, -1);
        }
        public static string SurgeonDropDown(string name, int? surgeonId)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<select name=\"").Append(name).Append("\">\n");

            foreach (Surgeon s in ConfigurationDAO.GetSurgeons())
            {
                sb.Append("<option value=\"").Append(s.surgeonID).Append("\" ");
                if (s.surgeonID == surgeonId)
                    sb.Append("selected=\"true\" ");
                sb.Append(">").Append(s.fName).Append(" ").Append(s.lName).Append("</option>\n");
            }

            sb.Append("</select>\n");
            return sb.ToString();
        }

        public static string SurgeonDropDown(string name)
        {
            return SurgeonDropDown(name, -1);
        }

    }

    
}
